﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DCSLibrary;
using Telerik.Web.UI;
using Utils.DC.Web.UI;

public partial class Admin_Module_quan_tri_quang_cao : System.Web.UI.UserControl
{
    #region Cac bien dung chung
    AdvUI objAdv = new AdvUI();
    DataSet dsAdv;
    #endregion

    #region Cac Ham Su Kien

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    protected void Ajax_Request(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            dsAdv = objAdv.GetAll();
            //if (!IsPostBack)
            //{
            BindGrid();
        }
    }

    protected void Adv_Delete(object source, GridCommandEventArgs e)
    {
        try
        {
            int id = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.Items[e.Item.ItemIndex]["AdvID"].Text.ToString());
            int result = objAdv.DeleteByID(id);
            if (result > 0)
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_SUCCESSFULLY;
                BindGrid();
            }
            else
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_NOT_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_NOT_SUCCESSFULLY;
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = MessageBox.MESSAGE_CONFILCT_DATA;
        }
    }
       
    #endregion

    #region Cac Ham Tuong Tac Du Lieu


    private void BindGrid()
    {
        try
        {
            dsAdv = objAdv.GetAll();
            grd.DataSource = dsAdv.Tables[0];
            grd.DataBind();
        }
        catch (Exception e)
        {

        }
    }

    #endregion
}
